
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>mysql索引与查询 · tgor note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tgor">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="mysql索引及查询.html" />
    
    
    <link rel="prev" href="mysql数据类型.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Me
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../category/微服务.html">
            
                <a href="../category/微服务.html">
            
                    
                    微服务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Java-Spring/Feign.html">
            
                <a href="../Java-Spring/Feign.html">
            
                    
                    HTTP客户端Feign
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Java-其他库/限流.html">
            
                <a href="../Java-其他库/限流.html">
            
                    
                    限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    限流Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../Java-Spring/负载均衡.html">
            
                <a href="../Java-Spring/负载均衡.html">
            
                    
                    负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    负载均衡Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../Java-其他库/熔断Hystrix.html">
            
                <a href="../Java-其他库/熔断Hystrix.html">
            
                    
                    熔断Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html#本地缓存">
            
                    
                    本地缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    分布式缓存Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html">
            
                    
                    分布式事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html#事务消息">
            
                    
                    可靠事务消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../Java-Spring/业务监控.html">
            
                <a href="../Java-Spring/业务监控.html">
            
                    
                    业务监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.13" data-path="../Java-其他库/分布式定时作业.html">
            
                <a href="../Java-其他库/分布式定时作业.html">
            
                    
                    分布式作业调度ElasticJob
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.14" data-path="../Java-ORM/ORM.html">
            
                <a href="../Java-ORM/ORM.html">
            
                    
                    ORM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.15" data-path="../Java-其他库/分布式系统及CAP原理.html">
            
                <a href="../Java-其他库/分布式系统及CAP原理.html">
            
                    
                    分布式系统及CAP原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.16" data-path="../MQ/RabbitMQ笔记.html">
            
                <a href="../MQ/RabbitMQ笔记.html">
            
                    
                    消息驱动Rabbitmq
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../category/数据库.html">
            
                <a href="../category/数据库.html">
            
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="经典数据库设计案例.html">
            
                <a href="经典数据库设计案例.html">
            
                    
                    mysql设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="Mysql事务与锁.html">
            
                <a href="Mysql事务与锁.html">
            
                    
                    mysql事务与锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="mysql数据类型.html">
            
                <a href="mysql数据类型.html">
            
                    
                    mysql数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.4" data-path="mysql索引及查询.html">
            
                <a href="mysql索引及查询.html">
            
                    
                    mysql索引与查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="mysql索引及查询.html">
            
                <a href="mysql索引及查询.html#查询语句设计准则">
            
                    
                    mysql查询语句设计准则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="mysql性能测试.html">
            
                <a href="mysql性能测试.html">
            
                    
                    mysql性能测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="mysql主从同步与读写分离.html">
            
                <a href="mysql主从同步与读写分离.html">
            
                    
                    mysql主从同步与读写分离
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                <a href="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                    
                    Spring事务注解@Transactional
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../数据结构与算法/位运算应用实例.html">
            
                <a href="../数据结构与算法/位运算应用实例.html">
            
                    
                    位运算应用实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../Mongodb-Client/morphia-API汇总.html">
            
                <a href="../Mongodb-Client/morphia-API汇总.html">
            
                    
                    morphia API汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../Mongodb-Client/mongo驱动连接.html">
            
                <a href="../Mongodb-Client/mongo驱动连接.html">
            
                    
                    mongodb驱动与连接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../Mongodb/mongodb-ObjectId实践.html">
            
                <a href="../Mongodb/mongodb-ObjectId实践.html">
            
                    
                    mongodb ObjectId实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="../Mongodb/mongodb角色权限.html">
            
                <a href="../Mongodb/mongodb角色权限.html">
            
                    
                    mongodb角色权限
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../category/java并发.html">
            
                <a href="../category/java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#锁">
            
                    
                    Java并发之锁设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#synchronized">
            
                    
                    Java并发之synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantlock">
            
                    
                    Java Lock之ReentrantLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantreadwritelock">
            
                    
                    Java Lock之ReentrantReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html">
            
                    
                    Java Future
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#futuretask">
            
                    
                    Java Future之FutureTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#completablefuture">
            
                    
                    Java Future之CompletableFuture
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#forkjointask">
            
                    
                    Java Future之ForkJoinTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../Java-Base/Java之Thread.html">
            
                <a href="../Java-Base/Java之Thread.html">
            
                    
                    Java Thread
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../category/redis.html">
            
                <a href="../category/redis.html">
            
                    
                    Redis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#集群">
            
                    
                    Redis集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#消息订阅">
            
                    
                    Redis消息订阅
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#lua">
            
                    
                    Redis Lua脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#配置汇总">
            
                    
                    Redis配置汇总
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../category/运维.html">
            
                <a href="../category/运维.html">
            
                    
                    运维
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../运维/Linux常用操作汇总.html">
            
                <a href="../运维/Linux常用操作汇总.html">
            
                    
                    Linux常用操作汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../运维/阿里云笔记.html">
            
                <a href="../运维/阿里云笔记.html">
            
                    
                    阿里云笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../category/nginx.html">
            
                <a href="../category/nginx.html">
            
                    
                    Nginx
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html">
            
                    
                    Nginx基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    Nginx负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    Nginx限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html#六、其他">
            
                    
                    Nginx客户端辅助技巧
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../category/容器化.html">
            
                <a href="../category/容器化.html">
            
                    
                    容器化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html">
            
                    
                    Docker学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#基础操作">
            
                    
                    Docker基础操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#dockerfile">
            
                    
                    DockerFile
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../category/Web.html">
            
                <a href="../category/Web.html">
            
                    
                    Web
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../运维/Http入坑Https笔记.html">
            
                <a href="../运维/Http入坑Https笔记.html">
            
                    
                    Http入坑Https笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../Web/阿里云OSS.html">
            
                <a href="../Web/阿里云OSS.html">
            
                    
                    OSS
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../category/java基础.html">
            
                <a href="../category/java基础.html">
            
                    
                    Java基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#jvm">
            
                    
                    JVM基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#语法糖">
            
                    
                    Java语法糖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#数据结构">
            
                    
                    Java数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../Java-Base/Java8函数式编程.html">
            
                <a href="../Java-Base/Java8函数式编程.html">
            
                    
                    java8函数式编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../Java-Base/ArrayList源码分析.html">
            
                <a href="../Java-Base/ArrayList源码分析.html">
            
                    
                    JDK源码分析ArrayList
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../Java-Base/HashMap源码分析.html">
            
                <a href="../Java-Base/HashMap源码分析.html">
            
                    
                    JDK源码分析HashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../Java-Base/Java注解.html">
            
                <a href="../Java-Base/Java注解.html">
            
                    
                    Java注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../Java-Base/Timsort排序算法.html">
            
                <a href="../Java-Base/Timsort排序算法.html">
            
                    
                    Timsort排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../Java-Base/插入排序分析与Java实现.html">
            
                <a href="../Java-Base/插入排序分析与Java实现.html">
            
                    
                    插入排序分析与Java实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../category/工具与规范.html">
            
                <a href="../category/工具与规范.html">
            
                    
                    工具与规范
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../工具/Maven使用技巧汇总.html">
            
                <a href="../工具/Maven使用技巧汇总.html">
            
                    
                    Maven使用技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../编码规范/Java编码规范.html">
            
                <a href="../编码规范/Java编码规范.html">
            
                    
                    Java编码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../category/OLAP.html">
            
                <a href="../category/OLAP.html">
            
                    
                    OLAP
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../数据处理/storm学习笔记.html">
            
                <a href="../数据处理/storm学习笔记.html">
            
                    
                    流式计算Storm学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../category/数据运营.html">
            
                <a href="../category/数据运营.html">
            
                    
                    数据运营
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../数据运营/增长黑客数据运营.html">
            
                <a href="../数据运营/增长黑客数据运营.html">
            
                    
                    增长黑客-数据运营
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../category/前端技术栈.html">
            
                <a href="../category/前端技术栈.html">
            
                    
                    前端技术栈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../前端/JavaScript设计模式.html">
            
                <a href="../前端/JavaScript设计模式.html">
            
                    
                    JavaScript设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../前端/html相对路径与绝对路径.html">
            
                <a href="../前端/html相对路径与绝对路径.html">
            
                    
                    Html相对路径与绝对路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../前端/微信小程序学习笔记.html">
            
                <a href="../前端/微信小程序学习笔记.html">
            
                    
                    微信小程序学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../category/个人.html">
            
                <a href="../category/个人.html">
            
                    
                    个人
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../个人/简历.html">
            
                <a href="../个人/简历.html">
            
                    
                    简历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >mysql索引与查询</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="mysql&#x7D22;&#x5F15;&#x53CA;&#x67E5;&#x8BE2;">Mysql&#x7D22;&#x5F15;&#x53CA;&#x67E5;&#x8BE2;</h1>
<p><a href="http://naotu.baidu.com/file/de817baf4c4e20b80925ed2855bba211?token=2e9d435af2aabca2" target="_blank">&#x7D22;&#x5F15;&#x4E0E;&#x67E5;&#x8BE2;&#x8111;&#x56FE;</a></p>
<h1 id="sql&#x811A;&#x672C;">sql&#x811A;&#x672C;</h1>
<h2 id="&#x6DFB;&#x52A0;&#x666E;&#x901A;&#x7D22;&#x5F15;">&#x6DFB;&#x52A0;&#x666E;&#x901A;&#x7D22;&#x5F15;</h2>
<p> <code>mysql&gt; alter table &#x8868;&#x540D; add index &#x7D22;&#x5F15;&#x540D; (&#x5B57;&#x6BB5;&#x540D;1[&#xFF0C;&#x5B57;&#x6BB5;&#x540D;2 &#x2026;]);</code>
&#x4F8B;&#x5B50;&#xFF1A; <code>mysql&gt; alter table employee add index emp_name (name);</code></p>
<h3 id="&#x6DFB;&#x52A0;&#x4E3B;&#x5173;&#x952E;&#x5B57;&#x7684;&#x7D22;&#x5F15;">&#x6DFB;&#x52A0;&#x4E3B;&#x5173;&#x952E;&#x5B57;&#x7684;&#x7D22;&#x5F15;</h3>
<p>  <code>mysql&gt; alter table &#x8868;&#x540D; add primary key (&#x5B57;&#x6BB5;&#x540D;);</code>
&#x4F8B;&#x5B50;&#xFF1A; <code>mysql&gt; alter table employee add primary key(id);</code></p>
<h3 id="&#x6DFB;&#x52A0;&#x552F;&#x4E00;&#x9650;&#x5236;&#x6761;&#x4EF6;&#x7684;&#x7D22;&#x5F15;"><strong>&#x6DFB;&#x52A0;&#x552F;&#x4E00;&#x9650;&#x5236;&#x6761;&#x4EF6;&#x7684;&#x7D22;&#x5F15;</strong></h3>
<p>  <code>mysql&gt; alter table &#x8868;&#x540D; add unique &#x7D22;&#x5F15;&#x540D; (&#x5B57;&#x6BB5;&#x540D;);</code>
&#x4F8B;&#x5B50;&#xFF1A;<code>mysql&gt; alter table employee add unique emp_name2(cardnumber);</code></p>
<h3 id="&#x5220;&#x9664;&#x67D0;&#x4E2A;&#x7D22;&#x5F15;">&#x5220;&#x9664;&#x67D0;&#x4E2A;&#x7D22;&#x5F15;**</h3>
<p>   <code>mysql&gt; alter table &#x8868;&#x540D; drop index &#x7D22;&#x5F15;&#x540D;;</code>
&#x4F8B;&#x5B50;&#xFF1A;<code>mysql&gt;alter table employee drop index emp_name;</code></p>
<h1 id="&#x7D22;&#x5F15;">&#x7D22;&#x5F15;</h1>
<h2 id="&#x4E8C;&#x53C9;&#x67E5;&#x627E;&#x6811;">&#x4E8C;&#x53C9;&#x67E5;&#x627E;&#x6811;</h2>
<p>&#x5B9A;&#x4E49;&#xFF1A;</p>
<ol>
<li>&#x5DE6;&#x53F6; &lt; &#x6839;</li>
<li>&#x53F3;&#x53F6; &gt; &#x6839;</li>
<li>&#x53EF;&#x4EE5;&#x4EFB;&#x52A1;&#x6784;&#x9020;</li>
</ol>
<p>&#x5982;&#x4E0B;&#xFF1A;&#x6709;&#x961F;&#x5217;<code>[2,3,5,6,7,8]</code></p>
<pre><code class="lang-java">    <span class="hljs-number">6</span>
   /  \
  <span class="hljs-number">3</span>    <span class="hljs-number">7</span>
 /  \   \
<span class="hljs-number">2</span>    <span class="hljs-number">5</span>   <span class="hljs-number">8</span>
</code></pre>
<p>&#x76EE;&#x6807;&#x627E;&#x5230;5&#xFF0C;&#x4ECE;&#x6839;6&#x5165;&#x624B;&#xFF0C;&#x627E;&#x5C0F;&#x7684;&#xFF0C;&#x5F97;&#x5230;&#x5DE6;&#x53F6;3&#xFF0C;&#x627E;&#x5927;&#x7684;&#xFF0C;&#x5F97;&#x5230;&#x53F3;&#x53F6;5&#x3002;&#x603B;&#x5171;&#x5BFB;&#x89C5;3&#x6B21;&#x3002;
&#x53EF;&#x4EE5;&#x5F97;&#x51FA;&#xFF0C;&#x8981;&#x627E;&#x51FA;&#x961F;&#x5217;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x503C;&#xFF0C;&#x9700;&#x8981;N&#x6B21;&#xFF1A;<code>N = 3 + 2 + 3 + 1 + 2 + 3 = 14 / 6 = 2.33</code>
&#x5982;&#x679C;&#x901A;&#x8FC7;&#x987A;&#x5E8F;&#x67E5;&#x8BE2;&#xFF0C;&#x9700;&#x8981;<code>N = (1 + 2 + 3 + 4 + 5 + 6) / 6 = 3.3</code></p>
<h2 id="&#x5E73;&#x8861;&#x4E8C;&#x53C9;&#x6811;&#xFF08;b-tree&#xFF09;">&#x5E73;&#x8861;&#x4E8C;&#x53C9;&#x6811;&#xFF08;B-Tree&#xFF09;</h2>
<p>&#x540C;&#x540D;&#xFF1A;B-Tree&#x3001;AVL&#x6811;</p>
<ol>
<li>&#x7B26;&#x5408;&#x4E8C;&#x53C9;&#x67E5;&#x627E;&#x6811;&#x7684;&#x5B9A;&#x4E49;</li>
<li>&#x4EFB;&#x4F55;&#x8282;&#x70B9;&#x7684;&#x4E24;&#x9897;&#x5B50;&#x6811;&#x7684;&#x9AD8;&#x5EA6;&#x6700;&#x5927;&#x5DEE;&#x4E3A;1</li>
</ol>
<p>&#x4E0B;&#x56FE;&#x4E3A;&#x4F4E;&#x6548;&#x7684;&#x4E00;&#x68F5;&#x4E8C;&#x53C9;&#x67E5;&#x627E;&#x6811;&#xFF0C;&#x904D;&#x5386;&#x5168;&#x503C;&#x9700;&#x8981;&#xFF1A;</p>
<pre><code class="lang-java">    <span class="hljs-number">2</span>
      \
       <span class="hljs-number">3</span>
        \
         <span class="hljs-number">5</span>
          \
           <span class="hljs-number">7</span>
          /  \
         <span class="hljs-number">6</span>    <span class="hljs-number">8</span>
</code></pre>
<h2 id="btree">B+Tree</h2>
<p>&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x4F7F;&#x7528;&#x6700;&#x4E3A;&#x9891;&#x7E41;&#x7684;&#x4E00;&#x79CD;&#x7D22;&#x5F15;&#x3002;</p>
<p>&#xFF08;1&#xFF09;&#x6240;&#x6709;&#x5173;&#x952E;&#x5B57;&#x90FD;&#x51FA;&#x73B0;&#x5728;&#x53F6;&#x5B50;&#x7ED3;&#x70B9;&#x7684;&#x94FE;&#x8868;&#x4E2D;&#xFF08;&#x7A20;&#x5BC6;&#x7D22;&#x5F15;&#xFF09;&#xFF0C;&#x4E14;&#x94FE;&#x8868;&#x4E2D;&#x7684;&#x5173;&#x952E;&#x5B57;&#x6070;&#x597D;&#x662F;&#x6709;&#x5E8F;&#x7684;&#xFF1B;&#xFF08;&#x53EA;&#x6709;&#x6839;&#x8282;&#x70B9;&#x5B58;&#x50A8;&#x5173;&#x952E;&#x5B57;&#x6700;&#x540E;&#x6811;&#x7684;&#x672B;&#x68A2;&#x624D;&#x6709;&#x503C;)
&#xFF08;2&#xFF09;&#x975E;&#x53F6;&#x5B50;&#x7ED3;&#x70B9;&#x76F8;&#x5F53;&#x4E8E;&#x662F;&#x53F6;&#x5B50;&#x7ED3;&#x70B9;&#x7684;&#x7D22;&#x5F15;&#xFF08;&#x7A00;&#x758F;&#x7D22;&#x5F15;&#xFF09;&#xFF0C;&#x53F6;&#x5B50;&#x7ED3;&#x70B9;&#x76F8;&#x5F53;&#x4E8E;&#x662F;&#x5B58;&#x50A8;&#xFF08;&#x5173;&#x952E;&#x5B57;&#xFF09;&#x6570;&#x636E;&#x7684;&#x6570;&#x636E;&#x5C42;&#x3002;&#xFF08;&#x975E;&#x6839;&#x8282;&#x70B9;&#xFF0C;&#x5B58;&#x50A8;&#x7684;&#x5176;&#x5B9E;&#x662F;&#x6307;&#x5411;&#x6839;&#x8282;&#x70B9;&#x7684;&#x7D22;&#x5F15;&#xFF09;
&#xFF08;3&#xFF09; &#x56E0;&#x4E3A;&#x524D;&#x4E24;&#x70B9;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x53EF;&#x80FD;&#x5728;&#x975E;&#x53F6;&#x5B50;&#x7ED3;&#x70B9;&#x5B58;&#x6570;&#x636E;&#x3002;(&#x533A;&#x522B;B-&#x7684;&#x7B2C;&#x4E09;&#x6761;)
&#xFF08;4&#xFF09;&#x6839;&#x8282;&#x70B9;&#x6A2A;&#x5411;&#x4E5F;&#x6709;&#x94FE;&#x6307;&#x9488;(&#x65B9;&#x4FBF;&#x5FEB;&#x901F;&#x987A;&#x85E4;&#x6478;&#x74DC;&#x561B;&#xFF0C;&#x6CA1;&#x8FD9;&#x4E2A;&#x6307;&#x9488;&#xFF0C;&#x5C31;&#x7B97;&#x4E0B;&#x4E00;&#x4E2A;&#x53D6;&#x7684;&#x503C;&#x662F;&#x6328;&#x7740;&#x7684;&#x90BB;&#x5C45;&#xFF0C;&#x4E5F;&#x5F97;&#x8DD1;&#x4E2A;&#x5708;&#x624D;&#x80FD;&#x62FF;&#x5230;)</p>
<h2 id="&#x547D;&#x4E2D;&#x7D22;&#x5F15;&#x6761;&#x4EF6;">&#x547D;&#x4E2D;&#x7D22;&#x5F15;&#x6761;&#x4EF6;</h2>
<p>1&#x3001;&#x5DE6;&#x6761;&#x4EF6;&#x8303;&#x56F4;&#x67E5;&#x8BE2;&#xFF0C;&#x53F3;&#x6761;&#x4EF6;&#x5168;&#x7B49;&#xFF1A;</p>
<p>&#x5DE6;&#x6761;&#x4EF6;&#x8303;&#x56F4;&#x503C;&#x5728;&#x5C11;&#x4E8E;&#x7B49;&#x4E8E;5&#x4E2A;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x547D;&#x4E2D;&#x7D22;&#x5F15;&#xFF0C;&#x8FDE;&#x63A5;&#x7C7B;&#x578B;&#x4E3A;range&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">explain</span>
<span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> red_packet <span class="hljs-keyword">where</span> business_id <span class="hljs-keyword">in</span> (<span class="hljs-string">&apos;1260809&apos;</span>,<span class="hljs-string">&apos;1260807&apos;</span>,<span class="hljs-string">&apos;dfd&apos;</span>,<span class="hljs-string">&apos;2934&apos;</span>,<span class="hljs-string">&apos;sdfw&apos;</span>,<span class="hljs-string">&apos;sdfds&apos;</span>) <span class="hljs-keyword">and</span> activity_code = <span class="hljs-string">&apos;investRed&apos;</span>

# <span class="hljs-keyword">id</span>, select_type, <span class="hljs-keyword">table</span>, <span class="hljs-keyword">partitions</span>, <span class="hljs-keyword">type</span>, possible_keys, <span class="hljs-keyword">key</span>, key_len, <span class="hljs-keyword">ref</span>, <span class="hljs-keyword">rows</span>, filtered, Extra
<span class="hljs-string">&apos;1&apos;</span>, <span class="hljs-string">&apos;SIMPLE&apos;</span>, <span class="hljs-string">&apos;red_packet&apos;</span>, <span class="hljs-literal">NULL</span>, <span class="hljs-string">&apos;range&apos;</span>, <span class="hljs-string">&apos;business_id&apos;</span>, <span class="hljs-string">&apos;business_id&apos;</span>, <span class="hljs-string">&apos;172&apos;</span>, <span class="hljs-literal">NULL</span>, <span class="hljs-string">&apos;6&apos;</span>, <span class="hljs-string">&apos;100.00&apos;</span>, <span class="hljs-string">&apos;Using index condition&apos;</span>
</code></pre>
<h2 id="&#x805A;&#x96C6;&#x4E0E;&#x975E;&#x805A;&#x96C6;&#x7D22;&#x5F15;">&#x805A;&#x96C6;&#x4E0E;&#x975E;&#x805A;&#x96C6;&#x7D22;&#x5F15;</h2>
<p><img src="assets/1574852623880.png" alt="1574852623880"></p>
<h1 id="explain">explain</h1>
<p>&#x5173;&#x4E8E;explain&#x5206;&#x6790;&#xFF1A;<a href="https://www.jianshu.com/p/e5232bdf3290" target="_blank">https://www.jianshu.com/p/e5232bdf3290</a></p>
<h2 id="selecttype">select_type</h2>
<p>&#x793A;&#x67E5;&#x8BE2;&#x4E2D;&#x6BCF;&#x4E2A;select&#x5B50;&#x53E5;&#x7684;&#x7C7B;&#x578B;</p>
<ul>
<li>SIMPLE(&#x7B80;&#x5355;SELECT,&#x4E0D;&#x4F7F;&#x7528;UNION&#x6216;&#x5B50;&#x67E5;&#x8BE2;&#x7B49;)</li>
<li>PRIMARY(&#x67E5;&#x8BE2;&#x4E2D;&#x82E5;&#x5305;&#x542B;&#x4EFB;&#x4F55;&#x590D;&#x6742;&#x7684;&#x5B50;&#x90E8;&#x5206;,&#x6700;&#x5916;&#x5C42;&#x7684;select&#x88AB;&#x6807;&#x8BB0;&#x4E3A;PRIMARY)</li>
<li>UNION(UNION&#x4E2D;&#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x6216;&#x540E;&#x9762;&#x7684;SELECT&#x8BED;&#x53E5;)</li>
<li>DEPENDENT UNION(UNION&#x4E2D;&#x7684;&#x7B2C;&#x4E8C;&#x4E2A;&#x6216;&#x540E;&#x9762;&#x7684;SELECT&#x8BED;&#x53E5;&#xFF0C;&#x53D6;&#x51B3;&#x4E8E;&#x5916;&#x9762;&#x7684;&#x67E5;&#x8BE2;)</li>
<li>UNION RESULT(UNION&#x7684;&#x7ED3;&#x679C;)</li>
<li>SUBQUERY(&#x5B50;&#x67E5;&#x8BE2;&#x4E2D;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;SELECT)</li>
<li>DEPENDENT SUBQUERY(&#x5B50;&#x67E5;&#x8BE2;&#x4E2D;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;SELECT&#xFF0C;&#x53D6;&#x51B3;&#x4E8E;&#x5916;&#x9762;&#x7684;&#x67E5;&#x8BE2;)</li>
<li>DERIVED(&#x6D3E;&#x751F;&#x8868;&#x7684;SELECT, FROM&#x5B50;&#x53E5;&#x7684;&#x5B50;&#x67E5;&#x8BE2;)</li>
<li>UNCACHEABLE SUBQUERY(&#x4E00;&#x4E2A;&#x5B50;&#x67E5;&#x8BE2;&#x7684;&#x7ED3;&#x679C;&#x4E0D;&#x80FD;&#x88AB;&#x7F13;&#x5B58;&#xFF0C;&#x5FC5;&#x987B;&#x91CD;&#x65B0;&#x8BC4;&#x4F30;&#x5916;&#x94FE;&#x63A5;&#x7684;&#x7B2C;&#x4E00;&#x884C;)</li>
</ul>
<h2 id="table">table</h2>
<p>&#x663E;&#x793A;&#x8FD9;&#x4E00;&#x884C;&#x7684;&#x6570;&#x636E;&#x662F;&#x5173;&#x4E8E;&#x54EA;&#x5F20;&#x8868;&#x7684;&#xFF0C;&#x6709;&#x65F6;&#x4E0D;&#x662F;&#x771F;&#x5B9E;&#x7684;&#x8868;&#x540D;&#x5B57;,&#x770B;&#x5230;&#x7684;&#x662F;derivedx(x&#x662F;&#x4E2A;&#x6570;&#x5B57;,&#x6211;&#x7684;&#x7406;&#x89E3;&#x662F;&#x7B2C;&#x51E0;&#x6B65;&#x6267;&#x884C;&#x7684;&#x7ED3;&#x679C;)</p>
<h2 id="type&#x8FDE;&#x63A5;&#x7C7B;&#x578B;">type&#x8FDE;&#x63A5;&#x7C7B;&#x578B;</h2>
<p><img src="assets/1574852350936.png" alt="1574852350936"></p>
<p>&#x8868;&#x793A;MySQL&#x5728;&#x8868;&#x4E2D;&#x627E;&#x5230;&#x6240;&#x9700;&#x884C;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x53C8;&#x79F0;&#x201C;&#x8BBF;&#x95EE;&#x7C7B;&#x578B;&#x201D;&#x3002;
<strong>&#x8FDE;&#x63A5;&#x7C7B;&#x578B;</strong>&#xFF1A;&#x5206;&#x522B;&#x4E3A;&#xFF1A;system/const/eq_ref/ref/range/index/All&#xFF0C;&#x6548;&#x7387;&#x4ECE;&#x524D;&#x5F80;&#x540E;&#x4E00;&#x6B21;&#x9012;&#x51CF;</p>
<ul>
<li><strong>ALL</strong>&#xFF1A;Full Table Scan&#xFF0C; MySQL&#x5C06;&#x904D;&#x5386;&#x5168;&#x8868;&#x4EE5;&#x627E;&#x5230;&#x5339;&#x914D;&#x7684;&#x884C;</li>
<li><strong>index</strong>: Full Index Scan&#xFF0C;index&#x4E0E;ALL&#x533A;&#x522B;&#x4E3A;index&#x7C7B;&#x578B;&#x53EA;&#x904D;&#x5386;&#x7D22;&#x5F15;&#x6811;&#x3002;&#x5728;&#x8FDB;&#x884C;&#x7EDF;&#x8BA1;&#x65F6;&#x975E;&#x5E38;&#x5E38;&#x89C1;&#xFF0C;&#x6B64;&#x8054;&#x63A5;&#x7C7B;&#x578B;&#x5B9E;&#x9645;&#x4E0A;&#x4F1A;&#x626B;&#x63CF;&#x7D22;&#x5F15;&#x6811;&#xFF0C;&#x4EC5;&#x6BD4;ALL&#x5FEB;&#x4E9B;&#x3002;</li>
<li><strong>range</strong>:&#x53EA;&#x68C0;&#x7D22;&#x7ED9;&#x5B9A;&#x8303;&#x56F4;&#x7684;&#x884C;&#xFF0C;&#x4F7F;&#x7528;&#x4E00;&#x4E2A;&#x7D22;&#x5F15;&#x6765;&#x9009;&#x62E9;&#x884C;</li>
<li><strong>ref</strong>: &#x8868;&#x793A;&#x4E0A;&#x8FF0;&#x8868;&#x7684;&#x8FDE;&#x63A5;&#x5339;&#x914D;&#x6761;&#x4EF6;&#xFF0C;&#x5373;&#x54EA;&#x4E9B;&#x5217;&#x6216;&#x5E38;&#x91CF;&#x88AB;&#x7528;&#x4E8E;&#x67E5;&#x627E;&#x7D22;&#x5F15;&#x5217;&#x4E0A;&#x7684;&#x503C;</li>
<li><strong>eq_ref</strong>: &#x7C7B;&#x4F3C;ref&#xFF0C;&#x533A;&#x522B;&#x5C31;&#x5728;&#x4F7F;&#x7528;&#x7684;&#x7D22;&#x5F15;&#x662F;&#x552F;&#x4E00;&#x7D22;&#x5F15;&#xFF0C;&#x5BF9;&#x4E8E;&#x6BCF;&#x4E2A;&#x7D22;&#x5F15;&#x952E;&#x503C;&#xFF0C;&#x8868;&#x4E2D;&#x53EA;&#x6709;&#x4E00;&#x6761;&#x8BB0;&#x5F55;&#x5339;&#x914D;&#xFF0C;&#x7B80;&#x5355;&#x6765;&#x8BF4;&#xFF0C;&#x5C31;&#x662F;&#x591A;&#x8868;&#x8FDE;&#x63A5;&#x4E2D;&#x4F7F;&#x7528;primary key&#x6216;&#x8005; unique key&#x4F5C;&#x4E3A;&#x5173;&#x8054;&#x6761;&#x4EF6;</li>
<li><strong>const</strong>: &#x8868;&#x6700;&#x591A;&#x6709;&#x4E00;&#x4E2A;&#x5339;&#x914D;&#x884C;,&#x5B83;&#x5C06;&#x5728;&#x67E5;&#x8BE2;&#x5F00;&#x59CB;&#x65F6;&#x88AB;&#x8BFB;&#x53D6;&#x3002;&#x56E0;&#x4E3A;&#x4EC5;&#x6709;&#x4E00;&#x884C;,&#x5728;&#x8FD9;&#x884C;&#x7684;&#x5217;&#x503C;&#x53EF;&#x88AB;&#x4F18;&#x5316;&#x5668;&#x5269;&#x4F59;&#x90E8;&#x5206;&#x8BA4;&#x4E3A;&#x662F;&#x5E38;&#x6570;&#x3002;const&#x8868;&#x5F88;&#x5FEB;,&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x53EA;&#x8BFB;&#x53D6;&#x4E00;&#x6B21;&#x3002;&#x5F53;MySQL&#x5BF9;&#x67E5;&#x8BE2;&#x67D0;&#x90E8;&#x5206;&#x8FDB;&#x884C;&#x4F18;&#x5316;&#xFF0C;&#x5E76;<strong>&#x8F6C;&#x6362;&#x4E3A;&#x4E00;&#x4E2A;&#x5E38;&#x91CF;</strong>&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x8FD9;&#x4E9B;&#x7C7B;&#x578B;&#x8BBF;&#x95EE;&#x3002;</li>
<li><strong>system</strong>&#xFF1A;&#x8868;&#x4EC5;&#x6709;&#x4E00;&#x884C;(=&#x7CFB;&#x7EDF;&#x8868;)&#x3002;&#x8FD9;&#x662F;const&#x8054;&#x63A5;&#x7C7B;&#x578B;&#x7684;&#x4E00;&#x4E2A;&#x7279;&#x4F8B;&#x3002;&#x5982;&#x5C06;&#x4E3B;&#x952E;&#x7F6E;&#x4E8E;where&#x5217;&#x8868;&#x4E2D;&#xFF0C;MySQL&#x5C31;&#x80FD;&#x5C06;&#x8BE5;&#x67E5;&#x8BE2;&#x8F6C;&#x6362;&#x4E3A;&#x4E00;&#x4E2A;&#x5E38;&#x91CF;,system&#x662F;const&#x7C7B;&#x578B;&#x7684;&#x7279;&#x4F8B;&#xFF0C;&#x5F53;&#x67E5;&#x8BE2;&#x7684;&#x8868;&#x53EA;&#x6709;&#x4E00;&#x884C;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4F7F;&#x7528;system</li>
<li><strong>NULL</strong>: MySQL&#x5728;&#x4F18;&#x5316;&#x8FC7;&#x7A0B;&#x4E2D;&#x5206;&#x89E3;&#x8BED;&#x53E5;&#xFF0C;&#x6267;&#x884C;&#x65F6;&#x751A;&#x81F3;&#x4E0D;&#x7528;&#x8BBF;&#x95EE;&#x8868;&#x6216;&#x7D22;&#x5F15;&#xFF0C;&#x4F8B;&#x5982;&#x4ECE;&#x4E00;&#x4E2A;&#x7D22;&#x5F15;&#x5217;&#x91CC;&#x9009;&#x53D6;&#x6700;&#x5C0F;&#x503C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5355;&#x72EC;&#x7D22;&#x5F15;&#x67E5;&#x627E;&#x5B8C;&#x6210;&#x3002;&#x4F8B;&#x5982;&#xFF1A;<code>select @rowNum:=0</code>&#x3002;</li>
</ul>
<h2 id="possiblekeys">possible_keys</h2>
<p>&#x6307;&#x51FA;MySQL&#x80FD;&#x4F7F;&#x7528;&#x54EA;&#x4E2A;&#x7D22;&#x5F15;&#x5728;&#x8868;&#x4E2D;&#x627E;&#x5230;&#x8BB0;&#x5F55;&#xFF0C;&#x67E5;&#x8BE2;&#x6D89;&#x53CA;&#x5230;&#x7684;&#x5B57;&#x6BB5;&#x4E0A;&#x82E5;&#x5B58;&#x5728;&#x7D22;&#x5F15;&#xFF0C;&#x5219;&#x8BE5;&#x7D22;&#x5F15;&#x5C06;&#x88AB;&#x5217;&#x51FA;&#xFF0C;&#x4F46;&#x4E0D;&#x4E00;&#x5B9A;&#x88AB;&#x67E5;&#x8BE2;&#x4F7F;&#x7528;</p>
<p>&#x8BE5;&#x5217;&#x5B8C;&#x5168;&#x72EC;&#x7ACB;&#x4E8E;EXPLAIN&#x8F93;&#x51FA;&#x6240;&#x793A;&#x7684;&#x8868;&#x7684;&#x6B21;&#x5E8F;&#x3002;&#x8FD9;&#x610F;&#x5473;&#x7740;&#x5728;possible_keys&#x4E2D;&#x7684;&#x67D0;&#x4E9B;&#x952E;&#x5B9E;&#x9645;&#x4E0A;&#x4E0D;&#x80FD;&#x6309;&#x751F;&#x6210;&#x7684;&#x8868;&#x6B21;&#x5E8F;&#x4F7F;&#x7528;&#x3002;
&#x5982;&#x679C;&#x8BE5;&#x5217;&#x662F;NULL&#xFF0C;&#x5219;&#x6CA1;&#x6709;&#x76F8;&#x5173;&#x7684;&#x7D22;&#x5F15;&#x3002;&#x5728;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x68C0;&#x67E5;WHERE&#x5B50;&#x53E5;&#x770B;&#x662F;&#x5426;&#x5B83;&#x5F15;&#x7528;&#x67D0;&#x4E9B;&#x5217;&#x6216;&#x9002;&#x5408;&#x7D22;&#x5F15;&#x7684;&#x5217;&#x6765;&#x63D0;&#x9AD8;&#x4F60;&#x7684;&#x67E5;&#x8BE2;&#x6027;&#x80FD;&#x3002;&#x5982;&#x679C;&#x662F;&#x8FD9;&#x6837;&#xFF0C;&#x521B;&#x9020;&#x4E00;&#x4E2A;&#x9002;&#x5F53;&#x7684;&#x7D22;&#x5F15;&#x5E76;&#x4E14;&#x518D;&#x6B21;&#x7528;EXPLAIN&#x68C0;&#x67E5;&#x67E5;&#x8BE2;</p>
<h2 id="key">Key</h2>
<p>key&#x5217;&#x663E;&#x793A;MySQL&#x5B9E;&#x9645;&#x51B3;&#x5B9A;&#x4F7F;&#x7528;&#x7684;&#x952E;&#xFF08;&#x7D22;&#x5F15;&#xFF09;</p>
<p>&#x5982;&#x679C;&#x6CA1;&#x6709;&#x9009;&#x62E9;&#x7D22;&#x5F15;&#xFF0C;&#x952E;&#x662F;NULL&#x3002;&#x8981;&#x60F3;&#x5F3A;&#x5236;MySQL&#x4F7F;&#x7528;&#x6216;&#x5FFD;&#x89C6;possible_keys&#x5217;&#x4E2D;&#x7684;&#x7D22;&#x5F15;&#xFF0C;&#x5728;&#x67E5;&#x8BE2;&#x4E2D;&#x4F7F;&#x7528;FORCE INDEX&#x3001;USE INDEX&#x6216;&#x8005;IGNORE INDEX&#x3002;</p>
<h2 id="keylen">key_len</h2>
<p>&#x8868;&#x793A;&#x7D22;&#x5F15;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x5B57;&#x8282;&#x6570;&#xFF0C;&#x53EF;&#x901A;&#x8FC7;&#x8BE5;&#x5217;&#x8BA1;&#x7B97;&#x67E5;&#x8BE2;&#x4E2D;&#x4F7F;&#x7528;&#x7684;&#x7D22;&#x5F15;&#x7684;&#x957F;&#x5EA6;&#xFF08;key_len&#x663E;&#x793A;&#x7684;&#x503C;&#x4E3A;&#x7D22;&#x5F15;&#x5B57;&#x6BB5;&#x7684;&#x6700;&#x5927;&#x53EF;&#x80FD;&#x957F;&#x5EA6;&#xFF0C;&#x5E76;&#x975E;&#x5B9E;&#x9645;&#x4F7F;&#x7528;&#x957F;&#x5EA6;&#xFF0C;&#x5373;key_len&#x662F;&#x6839;&#x636E;&#x8868;&#x5B9A;&#x4E49;&#x8BA1;&#x7B97;&#x800C;&#x5F97;&#xFF0C;&#x4E0D;&#x662F;&#x901A;&#x8FC7;&#x8868;&#x5185;&#x68C0;&#x7D22;&#x51FA;&#x7684;&#xFF09;</p>
<p>&#x4E0D;&#x635F;&#x5931;&#x7CBE;&#x786E;&#x6027;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x957F;&#x5EA6;&#x8D8A;&#x77ED;&#x8D8A;&#x597D; </p>
<h2 id="ref">ref</h2>
<p>&#x8868;&#x793A;&#x4E0A;&#x8FF0;&#x8868;&#x7684;&#x8FDE;&#x63A5;&#x5339;&#x914D;&#x6761;&#x4EF6;&#xFF0C;&#x5373;&#x54EA;&#x4E9B;&#x5217;&#x6216;&#x5E38;&#x91CF;&#x88AB;&#x7528;&#x4E8E;&#x67E5;&#x627E;&#x7D22;&#x5F15;&#x5217;&#x4E0A;&#x7684;&#x503C;</p>
<h2 id="rows">rows</h2>
<p>&#x8868;&#x793A;MySQL&#x6839;&#x636E;&#x8868;&#x7EDF;&#x8BA1;&#x4FE1;&#x606F;&#x53CA;&#x7D22;&#x5F15;&#x9009;&#x7528;&#x60C5;&#x51B5;&#xFF0C;&#x4F30;&#x7B97;&#x7684;&#x627E;&#x5230;&#x6240;&#x9700;&#x7684;&#x8BB0;&#x5F55;&#x6240;&#x9700;&#x8981;&#x8BFB;&#x53D6;&#x7684;&#x884C;&#x6570;</p>
<h2 id="extra">Extra</h2>
<p>&#x8BE5;&#x5217;&#x5305;&#x542B;MySQL&#x89E3;&#x51B3;&#x67E5;&#x8BE2;&#x7684;&#x8BE6;&#x7EC6;&#x4FE1;&#x606F;,&#x6709;&#x4EE5;&#x4E0B;&#x51E0;&#x79CD;&#x60C5;&#x51B5;&#xFF1A;</p>
<ul>
<li><strong>Using where</strong>:&#x5217;&#x6570;&#x636E;&#x662F;&#x4ECE;&#x4EC5;&#x4EC5;&#x4F7F;&#x7528;&#x4E86;&#x7D22;&#x5F15;&#x4E2D;&#x7684;&#x4FE1;&#x606F;&#x800C;&#x6CA1;&#x6709;&#x8BFB;&#x53D6;&#x5B9E;&#x9645;&#x7684;&#x884C;&#x52A8;&#x7684;&#x8868;&#x8FD4;&#x56DE;&#x7684;&#xFF0C;&#x8FD9;&#x53D1;&#x751F;&#x5728;&#x5BF9;&#x8868;&#x7684;&#x5168;&#x90E8;&#x7684;&#x8BF7;&#x6C42;&#x5217;&#x90FD;&#x662F;&#x540C;&#x4E00;&#x4E2A;&#x7D22;&#x5F15;&#x7684;&#x90E8;&#x5206;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8868;&#x793A;mysql&#x670D;&#x52A1;&#x5668;&#x5C06;&#x5728;&#x5B58;&#x50A8;&#x5F15;&#x64CE;&#x68C0;&#x7D22;&#x884C;&#x540E;&#x518D;&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;</li>
<li><strong>Using temporary</strong>&#xFF1A;&#x8868;&#x793A;MySQL&#x9700;&#x8981;&#x4F7F;&#x7528;&#x4E34;&#x65F6;&#x8868;&#x6765;&#x5B58;&#x50A8;&#x7ED3;&#x679C;&#x96C6;&#xFF0C;&#x5E38;&#x89C1;&#x4E8E;&#x6392;&#x5E8F;&#x548C;&#x5206;&#x7EC4;&#x67E5;&#x8BE2;</li>
<li><strong>Using filesort</strong>&#xFF1A;MySQL&#x4E2D;&#x65E0;&#x6CD5;&#x5229;&#x7528;&#x7D22;&#x5F15;&#x5B8C;&#x6210;&#x7684;&#x6392;&#x5E8F;&#x64CD;&#x4F5C;&#x79F0;&#x4E3A;&#x201C;&#x6587;&#x4EF6;&#x6392;&#x5E8F;&#x201D;</li>
<li><strong>Using join buffer</strong>&#xFF1A;&#x6539;&#x503C;&#x5F3A;&#x8C03;&#x4E86;&#x5728;&#x83B7;&#x53D6;&#x8FDE;&#x63A5;&#x6761;&#x4EF6;&#x65F6;&#x6CA1;&#x6709;&#x4F7F;&#x7528;&#x7D22;&#x5F15;&#xFF0C;&#x5E76;&#x4E14;&#x9700;&#x8981;&#x8FDE;&#x63A5;&#x7F13;&#x51B2;&#x533A;&#x6765;&#x5B58;&#x50A8;&#x4E2D;&#x95F4;&#x7ED3;&#x679C;&#x3002;&#x5982;&#x679C;&#x51FA;&#x73B0;&#x4E86;&#x8FD9;&#x4E2A;&#x503C;&#xFF0C;&#x90A3;&#x5E94;&#x8BE5;&#x6CE8;&#x610F;&#xFF0C;&#x6839;&#x636E;&#x67E5;&#x8BE2;&#x7684;&#x5177;&#x4F53;&#x60C5;&#x51B5;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x6DFB;&#x52A0;&#x7D22;&#x5F15;&#x6765;&#x6539;&#x8FDB;&#x80FD;&#x3002;</li>
<li><strong>Impossible where</strong>&#xFF1A;&#x8FD9;&#x4E2A;&#x503C;&#x5F3A;&#x8C03;&#x4E86;where&#x8BED;&#x53E5;&#x4F1A;&#x5BFC;&#x81F4;&#x6CA1;&#x6709;&#x7B26;&#x5408;&#x6761;&#x4EF6;&#x7684;&#x884C;&#x3002;</li>
<li><strong>Select tables optimized away</strong>&#xFF1A;&#x8FD9;&#x4E2A;&#x503C;&#x610F;&#x5473;&#x7740;&#x4EC5;&#x901A;&#x8FC7;&#x4F7F;&#x7528;&#x7D22;&#x5F15;&#xFF0C;&#x4F18;&#x5316;&#x5668;&#x53EF;&#x80FD;&#x4EC5;&#x4ECE;&#x805A;&#x5408;&#x51FD;&#x6570;&#x7ED3;&#x679C;&#x4E2D;&#x8FD4;&#x56DE;&#x4E00;&#x884C;</li>
</ul>
<h2 id="explain&#x603B;&#x7ED3;&#xFF1A;">explain&#x603B;&#x7ED3;&#xFF1A;</h2>
<ul>
<li>EXPLAIN&#x4E0D;&#x4F1A;&#x544A;&#x8BC9;&#x4F60;&#x5173;&#x4E8E;&#x89E6;&#x53D1;&#x5668;&#x3001;&#x5B58;&#x50A8;&#x8FC7;&#x7A0B;&#x7684;&#x4FE1;&#x606F;&#x6216;&#x7528;&#x6237;&#x81EA;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#x5BF9;&#x67E5;&#x8BE2;&#x7684;&#x5F71;&#x54CD;&#x60C5;&#x51B5;</li>
<li>EXPLAIN&#x4E0D;&#x8003;&#x8651;&#x5404;&#x79CD;Cache</li>
<li>EXPLAIN&#x4E0D;&#x80FD;&#x663E;&#x793A;MySQL&#x5728;&#x6267;&#x884C;&#x67E5;&#x8BE2;&#x65F6;&#x6240;&#x4F5C;&#x7684;&#x4F18;&#x5316;&#x5DE5;&#x4F5C;</li>
<li>&#x90E8;&#x5206;&#x7EDF;&#x8BA1;&#x4FE1;&#x606F;&#x662F;&#x4F30;&#x7B97;&#x7684;&#xFF0C;&#x5E76;&#x975E;&#x7CBE;&#x786E;&#x503C;</li>
<li>EXPALIN&#x53EA;&#x80FD;&#x89E3;&#x91CA;SELECT&#x64CD;&#x4F5C;&#xFF0C;&#x5176;&#x4ED6;&#x64CD;&#x4F5C;&#x8981;&#x91CD;&#x5199;&#x4E3A;SELECT&#x540E;&#x67E5;&#x770B;&#x6267;&#x884C;&#x8BA1;&#x5212;&#x3002;</li>
</ul>
<hr>
<h1 id="&#x67E5;&#x8BE2;&#x8BED;&#x53E5;&#x8BBE;&#x8BA1;&#x51C6;&#x5219;">&#x67E5;&#x8BE2;&#x8BED;&#x53E5;&#x8BBE;&#x8BA1;&#x51C6;&#x5219;</h1>
<p>&#x9488;&#x5BF9;<strong>OLTP</strong>&#x5E94;&#x7528;&#xFF0C;&#x6839;&#x636E;&#x7ECF;&#x9A8C;&#xFF0C;&#x5E94;&#x9075;&#x5FAA;&#x4EE5;&#x4E0B;&#x51C6;&#x5219;</p>
<p><strong>&#x6CE8;&#x610F;&#x662F;OLTP</strong></p>
<h2 id="1&#x3001;&#x7981;&#x6B62;&#x6CA1;&#x6709;&#x7D22;&#x5F15;&#x5B57;&#x6BB5;&#x67E5;&#x8BE2;&#x7684;&#x8303;&#x56F4;&#x67E5;&#x8BE2;">1&#x3001;&#x7981;&#x6B62;&#x6CA1;&#x6709;&#x7D22;&#x5F15;&#x5B57;&#x6BB5;<code>=</code>&#x67E5;&#x8BE2;&#x7684;&#x8303;&#x56F4;&#x67E5;&#x8BE2;</h2>
<p>&#x4F8B;&#x5982;</p>
<pre><code class="lang-sql">#customer_id&#x7D22;&#x5F15;
where customer_id &lt; x and &apos;2018-09-06 00:00:00&apos; &lt;= event_date and event_date &lt;= &apos;2018-09-06 01:00:00&apos;
</code></pre>
<h2 id="2&#x3001;&#x7981;&#x6B62;&#x4EFB;&#x4F55;&#x5B57;&#x6BB5;&#x5927;&#x8303;&#x56F4;&#x67E5;&#x8BE2;">2&#x3001;&#x7981;&#x6B62;&#x4EFB;&#x4F55;&#x5B57;&#x6BB5;&#x5927;&#x8303;&#x56F4;&#x67E5;&#x8BE2;</h2>
<pre><code class="lang-sql">#customer_id&#x7D22;&#x5F15;&#xFF0C;id&#x5927;&#x4E8E;100&#x6570;&#x636E;&#x91CF;&#x5360;&#x6BD4;&#x5927;&#xFF0C;&#x7B49;&#x540C;&#x5168;&#x8868;&#x626B;&#x63CF;
where customer_id &gt; 100

#age&#x975E;&#x7D22;&#x5F15;&#xFF0C;age30&#x4EE5;&#x4E0B;&#x53EF;&#x80FD;&#x6570;&#x636E;&#x91CF;&#x5360;&#x6BD4;&#x5927;&#xFF0C;&#x7B49;&#x540C;&#x5168;&#x8868;&#x626B;&#x63CF;
where age &lt; 30 

#customer_id&#x7D22;&#x5F15;&#xFF0C;in&#x8303;&#x56F4;&#x8FC7;&#x5927;&#xFF0C;&#x6548;&#x7387;&#x76F8;&#x5F53;&#x4F4E;
where customer_id in (a,b,c......) 
where customer_id not in (a,b,c......) 



#&#x8865;&#x5145;&#xFF0C;between &#x540C;&#x7406;&#xFF0C;&#x5982;&#x679C;&#x8303;&#x56F4;&#x8FC7;&#x5927;&#xFF0C;&#x7981;&#x6B62;&#x4F7F;&#x7528;&#xFF0C;&#x4F46;&#x5982;&#x679C;&#x8303;&#x56F4;&#x4E0D;&#x5927;&#xFF0C;&#x80FD;&#x7528;between&#x5C31;&#x4E0D;&#x8981;&#x7528;in 
where num between 1 and 3
</code></pre>
<h2 id="3&#x3001;&#x7981;&#x6B62;&#x4EFB;&#x4F55;&#x805A;&#x5408;&#x67E5;&#x8BE2;&#x4E0E;&#x6A21;&#x7CCA;&#x67E5;&#x8BE2;">3&#x3001;&#x7981;&#x6B62;&#x4EFB;&#x4F55;&#x805A;&#x5408;&#x67E5;&#x8BE2;&#x4E0E;&#x6A21;&#x7CCA;&#x67E5;&#x8BE2;</h2>
<pre><code class="lang-sql">#&#x6548;&#x7387;&#x4F4E;&#xFF0C;&#x4E0D;&#x7528;&#x8BF4;&#x4E86;
<span class="hljs-keyword">select</span> <span class="hljs-keyword">group_id</span>, <span class="hljs-keyword">max</span>(age) <span class="hljs-keyword">from</span> <span class="hljs-keyword">user</span> <span class="hljs-keyword">group</span> <span class="hljs-keyword">by</span> <span class="hljs-keyword">group_id</span>
</code></pre>
<h2 id="4&#x3001;&#x7981;&#x6B62;&#x901A;&#x8FC7;select-count&#x9A8C;&#x8BC1;&#x8BB0;&#x5F55;&#x662F;&#x5426;&#x5B58;&#x5728;">4&#x3001;&#x7981;&#x6B62;&#x901A;&#x8FC7;select count(*)&#x9A8C;&#x8BC1;&#x8BB0;&#x5F55;&#x662F;&#x5426;&#x5B58;&#x5728;</h2>
<p>select count(*)&#x53EF;&#x80FD;&#x89E6;&#x53D1;&#x5168;&#x8868;&#x626B;&#x63CF;&#xFF0C;&#x5E94;&#x8BE5;&#x91C7;&#x7528;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> <span class="hljs-number">1</span> <span class="hljs-keyword">from</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">where</span> condition <span class="hljs-keyword">limit</span> <span class="hljs-number">1</span>
</code></pre>
<h2 id="5&#x3001;&#x5EFA;&#x8BAE;&#x7EC4;&#x5408;&#x7D22;&#x5F15;&#xFF0C;&#x7C7B;&#x522B;&#x66F4;&#x591A;&#x7684;&#x5B57;&#x6BB5;&#xFF0C;&#x653E;&#x5DE6;&#x8FB9;">5&#x3001;&#x5EFA;&#x8BAE;&#x7EC4;&#x5408;&#x7D22;&#x5F15;&#xFF0C;&#x7C7B;&#x522B;&#x66F4;&#x591A;&#x7684;&#x5B57;&#x6BB5;&#xFF0C;&#x653E;&#x5DE6;&#x8FB9;</h2>
<pre><code class="lang-sql">#&#x7528;&#x6237;&#x8868;
where user_id = x and group_id = y

#&#x540C;&#x7406;&#xFF0C;&#x6D3B;&#x52A8;&#x8868;
where phone = x and activity_id = y

#&#x5982;&#x679C;&#x9700;&#x8981;&#x5355;&#x72EC;&#x67E5;&#x8BE2;&#x53F3;&#x8FB9;&#x5B57;&#x6BB5;&#xFF0C;&#x4F8B;&#x5982;&#x67E5;&#x8BE2;&#x6D3B;&#x52A8;&#x4E2D;&#x7684;&#x53C2;&#x4E0E;&#x624B;&#x673A;&#xFF0C;&#x5EFA;&#x8BAE;&#x589E;&#x52A0;&#x7D22;&#x5F15;
where activity_id = y
</code></pre>
<h2 id="6&#x3001;&#x5EFA;&#x8BAE;or&#x64CD;&#x4F5C;&#x7B26;&#x5FC5;&#x987B;&#x6BCF;&#x4E2A;&#x5B57;&#x6BB5;&#x90FD;&#x5EFA;&#x7ACB;&#x7D22;&#x5F15;">6&#x3001;&#x5EFA;&#x8BAE;or&#x64CD;&#x4F5C;&#x7B26;&#x5FC5;&#x987B;&#x6BCF;&#x4E2A;&#x5B57;&#x6BB5;&#x90FD;&#x5EFA;&#x7ACB;&#x7D22;&#x5F15;</h2>
<h2 id="7&#x3001;&#x907F;&#x514D;&#x5BF9;&#x5B57;&#x6BB5;&#x8FDB;&#x884C;null&#x5224;&#x65AD;">7&#x3001;&#x907F;&#x514D;&#x5BF9;&#x5B57;&#x6BB5;&#x8FDB;&#x884C;null&#x5224;&#x65AD;</h2>
<pre><code class="lang-sql"><span class="hljs-keyword">select</span> <span class="hljs-keyword">id</span> <span class="hljs-keyword">from</span> t <span class="hljs-keyword">where</span> <span class="hljs-keyword">num</span> <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span>;
</code></pre>
<h2 id="8&#x3001;&#x7981;&#x6B62;&#x5BF9;&#x5B57;&#x6BB5;&#x8FDB;&#x884C;&#x8868;&#x8FBE;&#x5F0F;&#x6216;&#x51FD;&#x6570;&#x64CD;&#x4F5C;">8&#x3001;&#x7981;&#x6B62;&#x5BF9;&#x5B57;&#x6BB5;&#x8FDB;&#x884C;&#x8868;&#x8FBE;&#x5F0F;&#x6216;&#x51FD;&#x6570;&#x64CD;&#x4F5C;</h2>
<pre><code class="lang-sql">where num/2 = 100;

where substring(name, 1, 3) = &#x2019;abc&#x2019;;

where datediff(day,createdate,&#x2019;2005-11-30&#x2032;) = 0&#x2013;&#x2019;2005-11-30&#x2032;;
</code></pre>
<h2 id="9&#x3001;&#x907F;&#x514D;&#x7D22;&#x5F15;&#x6570;&#x91CF;&#x8D85;&#x8FC7;2&#x4E2A;">9&#x3001;&#x907F;&#x514D;&#x7D22;&#x5F15;&#x6570;&#x91CF;&#x8D85;&#x8FC7;2&#x4E2A;</h2>
<p>&#x907F;&#x514D;&#x5F71;&#x54CD;insert update&#x6027;&#x80FD;</p>
<h2 id="10&#x3001;&#x7981;&#x6B62;&#x4EFB;&#x4F55;&#x5730;&#x65B9;&#x51FA;&#x73B0;select-&#x8BED;&#x53E5;">10&#x3001;&#x7981;&#x6B62;&#x4EFB;&#x4F55;&#x5730;&#x65B9;&#x51FA;&#x73B0;<code>select *</code>&#x8BED;&#x53E5;</h2>
<ul>
<li>select *&#x53EF;&#x80FD;&#x8FD4;&#x56DE;&#x65E0;&#x6548;&#x5B57;&#x6BB5;</li>
<li>&#x5F53;&#x8868;&#x7ED3;&#x6784;&#x53D8;&#x66F4;&#x65F6;&#xFF0C;&#x90E8;&#x5206;ORM&#x6846;&#x67B6;&#x53EF;&#x80FD;&#x4E0D;&#x80FD;&#x517C;&#x5BB9;&#xFF0C;&#x5BFC;&#x81F4;&#x62A5;&#x9519;</li>
<li>&#x6D4B;&#x8BD5;&#x8BED;&#x53E5;&#x6216;&#x751F;&#x4EA7;&#x5E93;&#x64CD;&#x4F5C;&#x8BED;&#x53E5;&#x90FD;&#x4E0D;&#x8981;&#x51FA;&#x73B0;&#xFF0C;&#x5982;&#x679C;&#x8868;&#x6570;&#x636E;&#x91CF;&#x8D85;2000&#x4E07;&#xFF0C;&#x5168;&#x8868;&#x626B;&#x63CF;&#x53EF;&#x80FD;&#x5F71;&#x54CD;&#x524D;&#x53F0;&#x76F8;&#x5173;&#x5171;&#x97A5;&#x4F60;</li>
</ul>
<h1 id="&#x8303;&#x56F4;&#x67E5;&#x8BE2;&#x4E0E;&#x7D22;&#x5F15;">&#x8303;&#x56F4;&#x67E5;&#x8BE2;&#x4E0E;&#x7D22;&#x5F15;</h1>
<p>&#x8303;&#x56F4;&#x67E5;&#x8BE2;&#x4E0E;&#x5E38;&#x91CF;&#x8F6C;&#x6362;&#x793A;&#x4F8B;&#xFF1A;<a href="https://blog.csdn.net/itas109/article/details/79150550" target="_blank">https://blog.csdn.net/itas109/article/details/79150550</a></p>
<p>&#x8FDE;&#x63A5;&#x7C7B;&#x578B;&#x4E0E;&#x7D22;&#x5F15;</p>
<pre><code class="lang-sql"><span class="hljs-keyword">explain</span>
<span class="hljs-keyword">select</span> * <span class="hljs-keyword">from</span> suzaku_event_log
#const&#xFF0C;<span class="hljs-keyword">id</span>&#x4E3A;&#x4E3B;&#x952E;&#x7D22;&#x5F15;&#xFF0C;&#x8868;&#x6700;&#x591A;&#x6709;&#x4E00;&#x4E2A;&#x5339;&#x914D;&#x884C;,&#x5B83;&#x5C06;&#x5728;&#x67E5;&#x8BE2;&#x5F00;&#x59CB;&#x65F6;&#x88AB;&#x8BFB;&#x53D6;&#x3002;&#x56E0;&#x4E3A;&#x4EC5;&#x6709;&#x4E00;&#x884C;,&#x5728;&#x8FD9;&#x884C;&#x7684;&#x5217;&#x503C;&#x53EF;&#x88AB;&#x4F18;&#x5316;&#x5668;&#x5269;&#x4F59;&#x90E8;&#x5206;&#x8BA4;&#x4E3A;&#x662F;&#x5E38;&#x6570;&#x3002;const&#x8868;&#x5F88;&#x5FEB;,&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x53EA;&#x8BFB;&#x53D6;&#x4E00;&#x6B21;!
<span class="hljs-keyword">where</span> <span class="hljs-keyword">id</span> = <span class="hljs-string">&apos;123&apos;</span> 

#<span class="hljs-keyword">range</span>&#xFF0C;<span class="hljs-keyword">id</span>&#x4E3A;&#x4E3B;&#x952E;&#x7D22;&#x5F15;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x7D22;&#x5F15;&#x4E0A;&#x6309;&#x6307;&#x5B9A;&#x7684;&#x8303;&#x56F4;&#x8FDB;&#x884C;&#x68C0;&#x7D22;
<span class="hljs-keyword">where</span> <span class="hljs-keyword">id</span> <span class="hljs-keyword">in</span> (<span class="hljs-string">&apos;123&apos;</span>,<span class="hljs-string">&apos;124&apos;</span>)

#all&#xFF0C;source_id&#x975E;&#x7D22;&#x5F15;&#xFF0C;&#x5168;&#x8868;&#x641C;&#x7D22;
<span class="hljs-keyword">where</span> source_id <span class="hljs-keyword">in</span> (<span class="hljs-string">&apos;sid123&apos;</span>)

#<span class="hljs-keyword">ref</span>&#xFF0C;customer_id&#x4E3A;&#x666E;&#x901A;&#x7D22;&#x5F15;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x7D22;&#x5F15;&#x4E0A;&#x6309;&#x6307;&#x5B9A;&#x7684;&#x8303;&#x56F4;&#x8FDB;&#x884C;&#x68C0;&#x7D22;
<span class="hljs-keyword">where</span> customer_id = <span class="hljs-string">&apos;cid123&apos;</span>  

#<span class="hljs-keyword">range</span>&#xFF0C;customer_id&#x4E0E;event_date&#x7EC4;&#x5408;&#x7D22;&#x5F15;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x7D22;&#x5F15;&#x4E0A;&#x6309;&#x6307;&#x5B9A;&#x7684;&#x8303;&#x56F4;&#x8FDB;&#x884C;&#x68C0;&#x7D22;
<span class="hljs-keyword">where</span> customer_id = <span class="hljs-string">&apos;cid124&apos;</span> <span class="hljs-keyword">and</span> <span class="hljs-string">&apos;2018-09-06 00:00:00&apos;</span> &lt;= event_date <span class="hljs-keyword">and</span> event_date &lt;= <span class="hljs-string">&apos;2018-09-06 01:00:00&apos;</span>

#<span class="hljs-keyword">range</span>&#xFF0C;customer_id&#x4E0E;event_date&#x7EC4;&#x5408;&#x7D22;&#x5F15;&#xFF0C;&#x6700;&#x5DE6;&#x4F7F;&#x7528; = &lt; &#x3001;&lt;=#.&#x53EF;&#x4EE5;&#x5728;&#x7D22;&#x5F15;&#x4E0A;&#x6309;&#x6307;&#x5B9A;&#x7684;&#x8303;&#x56F4;&#x8FDB;&#x884C;&#x68C0;&#x7D22;&#xFF0C;
<span class="hljs-keyword">where</span> customer_id &gt; <span class="hljs-string">&apos;cid124&apos;</span> <span class="hljs-keyword">and</span> <span class="hljs-string">&apos;2018-09-06 00:00:00&apos;</span> &lt;= event_date <span class="hljs-keyword">and</span> event_date &lt;= <span class="hljs-string">&apos;2018-09-06 01:00:00&apos;</span>

#all&#xFF0C;&#x53F3;&#x6761;&#x4EF6;&#x975E;&#x7D22;&#x5F15;&#x8303;&#x56F4;&#x67E5;&#x8BE2;&#xFF0C;&#x5168;&#x8868;&#x7D22;&#x5F15;
<span class="hljs-keyword">where</span> customer_id = <span class="hljs-string">&apos;cid124&apos;</span> <span class="hljs-keyword">and</span> source_id &lt; <span class="hljs-string">&apos;sid123&apos;</span>
</code></pre>
<p>&#x8054;&#x5408;&#x7D22;&#x5F15;&#x6709;&#x505A;&#x5339;&#x914D;&#x539F;&#x5219;&#xFF0C;&#x5047;&#x8BBE;&#x8054;&#x5408;&#x7D22;&#x5F15;&#x4E3A;&#xFF08;a&#xFF0C;b&#xFF09;</p>
<p>&#x53EF;&#x4EE5;&#x547D;&#x4E2D;&#x7D22;&#x5F15;&#x573A;&#x666F;</p>
<p>&#x5DE6;&#x53F3;&#x6761;&#x4EF6;&#x90FD;&#x76F8;&#x7B49;&#xFF1A;a= x and b=y</p>
<p>&#x5DE6;&#x8FB9;&#x6761;&#x4EF6;&#x8F83;&#x5C11;&#x8303;&#x56F4;&#x67E5;&#x8BE2;&#xFF1A; a in (x, y , z)</p>
<p>&#x5DE6;&#x8FB9;&#x6761;&#x4EF6;&#x76F8;&#x7B49;&#xFF0C;&#x53F3;&#x8FB9;&#x6761;&#x4EF6;&#x8F83;&#x5C11;&#x8303;&#x56F4;&#x67E5;&#x8BE2;&#xFF1A;a = x and b&gt; y</p>
<p>&#x4EE5;&#x5DE6;&#x8FB9;&#x6761;&#x4EF6;&#x6392;&#x5E8F;&#x5E76;&#x9650;&#x5236;&#x8FD4;&#x56DE;&#x8F83;&#x5C11;&#x6761;&#x6570;&#xFF1A;order by a limit 10</p>
<p>&#x4E0D;&#x80FD;&#x547D;&#x4E2D;&#x7D22;&#x5F15;&#x573A;&#x666F;</p>
<p>&#x5DE6;&#x8FB9;&#x6761;&#x4EF6;&#x4E0D;&#x76F8;&#x7B49;&#xFF1A;a&lt;&gt;x</p>
<p>&#x5DE6;&#x8FB9;&#x6761;&#x4EF6;&#x4E3A;&#x5927;&#x8303;&#x56F4;&#x67E5;&#x8BE2;&#x3001;&#x6A21;&#x7CCA;&#x67E5;&#x8BE2;&#x3001;&#x7A7A;&#x503C;&#x5224;&#x65AD;&#x7B49;:a in (x, y, z)    ; a like x;   a is null</p>
<p>&#x5DE6;&#x8FB9;&#x6761;&#x4EF6;&#x76F8;&#x7B49;&#xFF0C;&#x53F3;&#x8FB9;&#x6761;&#x4EF6;&#x8F83;&#x5927;&#x8303;&#x56F4;&#x67E5;&#x8BE2;&#xFF1A;a = x and b&gt; y</p>
<p>&#x4EE5;&#x53F3;&#x8FB9;&#x6761;&#x4EF6;&#x4F5C;&#x4E3A;&#x9996;&#x8981;&#x6392;&#x5E8F;&#x6761;&#x4EF6;&#x3001;&#x5DE6;&#x8FB9;&#x4E3A;&#x6B21;&#x8981;&#x6392;&#x5E8F;&#x6761;&#x4EF6;&#xFF1A;order by b,a</p>
<p>&#x4EE5;&#x5DE6;&#x8FB9;&#x6761;&#x4EF6;&#x6392;&#x5E8F;&#x5E76;&#x9650;&#x5236;&#x8FD4;&#x56DE;&#x8F83;&#x591A;&#x6761;&#x6570;&#xFF1A;order by a limit 10000</p>
<h2 id="join-on">join on</h2>
<h2 id="on&#x4E0E;where&#x7684;&#x6267;&#x884C;&#x987A;&#x5E8F;">on&#x4E0E;where&#x7684;&#x6267;&#x884C;&#x987A;&#x5E8F;</h2>
<p>ON &#x6761;&#x4EF6;&#xFF08;&#x201C;A LEFT JOIN B ON &#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&#x201D;&#x4E2D;&#x7684;ON&#xFF09;&#x7528;&#x6765;&#x51B3;&#x5B9A;&#x5982;&#x4F55;&#x4ECE; B &#x8868;&#x4E2D;&#x68C0;&#x7D22;&#x6570;&#x636E;&#x884C;&#x3002;&#x5982;&#x679C; B &#x8868;&#x4E2D;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x4E00;&#x884C;&#x6570;&#x636E;&#x5339;&#x914D; ON &#x7684;&#x6761;&#x4EF6;,&#x5C06;&#x4F1A;&#x989D;&#x5916;&#x751F;&#x6210;&#x4E00;&#x884C;&#x6240;&#x6709;&#x5217;&#x4E3A; NULL &#x7684;&#x6570;&#x636E;,&#x5728;&#x5339;&#x914D;&#x9636;&#x6BB5; WHERE &#x5B50;&#x53E5;&#x7684;&#x6761;&#x4EF6;&#x90FD;&#x4E0D;&#x4F1A;&#x88AB;&#x4F7F;&#x7528;&#x3002;&#x4EC5;&#x5728;&#x5339;&#x914D;&#x9636;&#x6BB5;&#x5B8C;&#x6210;&#x4EE5;&#x540E;&#xFF0C;WHERE &#x5B50;&#x53E5;&#x6761;&#x4EF6;&#x624D;&#x4F1A;&#x88AB;&#x4F7F;&#x7528;&#x3002;&#x5B83;&#x5C06;&#x4ECE;&#x5339;&#x914D;&#x9636;&#x6BB5;&#x4EA7;&#x751F;&#x7684;&#x6570;&#x636E;&#x4E2D;&#x68C0;&#x7D22;&#x8FC7;&#x6EE4;&#x3002;</p>
<blockquote>
<p><strong>note1&#xFF1A;</strong>&#x5728;&#x4F7F;&#x7528;left&#xFF08;right&#xFF09;join&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E00;&#x5B9A;&#x8981;&#x5148;&#x7ED9;&#x51FA;&#x5C3D;&#x53EF;&#x80FD;&#x591A;&#x7684;&#x5339;&#x914D;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#xFF0C;&#x51CF;&#x5C11;where&#x7684;&#x6267;&#x884C;&#x3002;</p>
<p><strong>note2:</strong>&#x6CE8;&#x610F;ON &#x5B50;&#x53E5;&#x548C; WHERE &#x5B50;&#x53E5;&#x7684;&#x4E0D;&#x540C;&#x3002;&#x770B;&#x4EE5;&#x4E0B;&#x4F8B;&#x5B50;</p>
</blockquote>
<pre><code>mysql&gt; SELECT * FROM product LEFT JOIN product_details
       ON (product.id = product_details.id)
       AND product_details.id=2;
+----+--------+------+--------+-------+
| id | amount | id   | weight | exist |
+----+--------+------+--------+-------+
|  1 |    100 | NULL |   NULL |  NULL |
|  2 |    200 |    2 |     22 |     0 |
|  3 |    300 | NULL |   NULL |  NULL |
|  4 |    400 | NULL |   NULL |  NULL |
+----+--------+------+--------+-------+
4 rows in set (0.00 sec)

mysql&gt; SELECT * FROM product LEFT JOIN product_details
       ON (product.id = product_details.id)
       WHERE product_details.id=2;
+----+--------+----+--------+-------+
| id | amount | id | weight | exist |
+----+--------+----+--------+-------+
|  2 |    200 |  2 |     22 |     0 |
+----+--------+----+--------+-------+
1 row in set (0.01 sec)
</code></pre><p>ALTER TABLE <code>jpress</code>.<code>article</code> 
ADD INDEX <code>question_id</code> (<code>question_id</code> DESC);</p>
<p>ALTER TABLE <code>jpress</code>.<code>article</code> 
DROP INDEX <code>check_date</code> ;</p>
<p>ALTER TABLE <code>jpress</code>.<code>article</code> 
DROP INDEX <code>order_number</code> ,
ADD INDEX <code>order_number_agree_count</code> (<code>order_number</code> DESC, <code>agree_count</code> DESC),
DROP INDEX <code>view_count</code> ;</p>
<p><img src="assets/1582364622414.png" alt="1582364622414"></p>
<p><img src="assets/1582364599374.png" alt="1582364599374"></p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; tgor.top 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-04-23 15:32:53
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="mysql数据类型.html" class="navigation navigation-prev " aria-label="Previous page: mysql数据类型">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="mysql索引及查询.html#查询语句设计准则" class="navigation navigation-next " aria-label="Next page: mysql查询语句设计准则">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"mysql索引与查询","level":"1.3.4","depth":2,"next":{"title":"mysql查询语句设计准则","level":"1.3.5","depth":2,"anchor":"#查询语句设计准则","path":"Mysql/mysql索引及查询.md","ref":"Mysql/mysql索引及查询.md#查询语句设计准则","articles":[]},"previous":{"title":"mysql数据类型","level":"1.3.3","depth":2,"path":"Mysql/mysql数据类型.md","ref":"Mysql/mysql数据类型.md","articles":[]},"dir":"ltr"},"config":{"plugins":["chapter-fold","splitter","tbfed-pagefooter","page-toc-button","-search","search-pro","popup","back-to-top-button","code","copy-code-button"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy tgor.top 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"sepia","family":"serif","size":1},"highlight":{},"page-toc-button":{"maxTocDepth":2,"minTocSize":2},"back-to-top-button":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tgor","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"tgor note","gitbook":"*","description":"tgor生活工作记录"},"file":{"path":"Mysql/mysql索引及查询.md","mtime":"2020-04-23T07:32:53.361Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-29T08:43:24.127Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

